import time

from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

TIMEOUT=10
class Page:

    def __init__(self,driver :WebDriver):
        self.driver = driver

    #浏览器
    def goto(self,url):
        self.driver.get(url)
    #关闭浏览器
    def close(self):
        time.sleep(5)
        self.driver.close()

    #等待
    def wait_time(self,loc,timeout = None) ->WebElement:
        timeout=TIMEOUT if timeout is None else timeout
        wait= WebDriverWait(self.driver,timeout=timeout)
        return wait.until(expected_conditions.element_to_be_clickable(loc))
    #点击操作
    def click(self,loc):
        tr=self.wait_time(loc)
        tr.click()
    #输入操作
    def fill(self,loc,value):
        tr=self.wait_time(loc)
        tr.send_keys(value)
    #时间
    def sleep_time(self,waittime):
        time.sleep(waittime)
    #获取文本元素
    def get_text(self,loc):
        return self.wait_time(loc).text
